From 5de3b0d5b509ca7be58b0bdb8dbadc70a5fb898f Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20H=C3=A4rdeman?= Date: Wed, 8 Oct 2025 07:27:08 +0200 Subject: [PATCH] odhcpd: add log helpers MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit These a just a bit more succinct than their syslog equivalents. Also, this lays the ground for the next patch. Signed-off-by: David Härdeman Link: https://github.com/openwrt/odhcpd/pull/273 Signed-off-by: Álvaro Fernández Rojas --- src/config.c | 195 ++++++++++++++++++++++------------------------- src/dhcpv4.c | 83 ++++++++++---------- src/dhcpv6-ia.c | 24 +++--- src/dhcpv6-pxe.c | 11 ++- src/dhcpv6.c | 38 ++++----- src/ndp.c | 46 +++++------ src/netlink.c | 17 ++--- src/odhcpd.c | 18 ++--- src/odhcpd.h | 16 ++++ src/router.c | 108 +++++++++++++------------- src/ubus.c | 3 +- 11 files changed, 277 insertions(+), 282 deletions(-) diff --git a/src/config.c b/src/config.c index 2d8ff01..0bcae10 100644 --- a/src/config.c +++ b/src/config.c @@ -8,7 +8,6 @@ #include #include #include -#include #include #include @@ -479,14 +478,14 @@ static bool parse_duid(struct duid *duid, struct blob_attr *c) /* IAID = uint32, RFC8415, §21.4, §21.5, §21.21 */ if (iaid_str_len < 1 || iaid_str_len > 2 * sizeof(uint32_t)) { - syslog(LOG_ERR, "Invalid IAID length '%s'", iaid_str); + error("Invalid IAID length '%s'", iaid_str); return false; } errno = 0; duid->iaid = strtoul(iaid_str, &end, 16); if (errno || *end != '\0') { - syslog(LOG_ERR, "Invalid IAID '%s'", iaid_str); + error("Invalid IAID '%s'", iaid_str); return false; } @@ -495,13 +494,13 @@ static bool parse_duid(struct duid *duid, struct blob_attr *c) } if (duid_str_len < 2 || duid_str_len > DUID_MAX_LEN * 2 || duid_str_len % 2) { - syslog(LOG_ERR, "Invalid DUID length '%.*s'", (int)duid_str_len, duid_str); + error("Invalid DUID length '%.*s'", (int)duid_str_len, duid_str); return false; } duid_len = odhcpd_unhexlify(duid->id, duid_str_len / 2, duid_str); if (duid_len < 0) { - syslog(LOG_ERR, "Invalid DUID '%.*s'", (int)duid_str_len, duid_str); + error("Invalid DUID '%.*s'", (int)duid_str_len, duid_str); return false; } @@ -690,10 +689,10 @@ static int parse_dnr_str(char *str, struct interface *iface) if (!priority) { goto err; } else if (sscanf(priority, "%" SCNu16, &dnr.priority) != 1) { - syslog(LOG_ERR, "Unable to parse priority '%s'", priority); + error("Unable to parse priority '%s'", priority); goto err; } else if (dnr.priority == 0) { - syslog(LOG_ERR, "Invalid priority '%s'", priority); + error("Invalid priority '%s'", priority); goto err; } @@ -707,13 +706,13 @@ static int parse_dnr_str(char *str, struct interface *iface) adn[adn_len - 1] = '\0'; if (adn_len >= sizeof(adn_buf)) { - syslog(LOG_ERR, "Hostname '%s' too long", adn); + error("Hostname '%s' too long", adn); goto err; } adn_len = dn_comp(adn, adn_buf, sizeof(adn_buf), NULL, NULL); if (adn_len <= 0) { - syslog(LOG_ERR, "Unable to parse hostname '%s'", adn); + error("Unable to parse hostname '%s'", adn); goto err; } @@ -757,7 +756,7 @@ static int parse_dnr_str(char *str, struct interface *iface) dnr.addr4_cnt++; } else { - syslog(LOG_ERR, "Unable to parse IP address '%s'", addr); + error("Unable to parse IP address '%s'", addr); goto err; } } @@ -774,7 +773,7 @@ static int parse_dnr_str(char *str, struct interface *iface) uint32_t lifetime; if (!svc_val || sscanf(svc_val, "%" SCNu32, &lifetime) != 1) { - syslog(LOG_ERR, "Invalid value '%s' for _lifetime", svc_val ? svc_val : ""); + error("Invalid value '%s' for _lifetime", svc_val ? svc_val : ""); goto err; } @@ -788,7 +787,7 @@ static int parse_dnr_str(char *str, struct interface *iface) break; if (svc_id >= DNR_SVC_MAX) { - syslog(LOG_ERR, "Invalid SvcParam '%s'", svc_key); + error("Invalid SvcParam '%s'", svc_key); goto err; } @@ -818,7 +817,7 @@ static int parse_dnr_str(char *str, struct interface *iface) break; if (mkey >= DNR_SVC_MAX || !svc_vals[mkey]) { - syslog(LOG_ERR, "Invalid value '%s' for SvcParam 'mandatory'", mkey_str); + error("Invalid value '%s' for SvcParam 'mandatory'", mkey_str); goto err; } @@ -858,7 +857,7 @@ static int parse_dnr_str(char *str, struct interface *iface) alpn_id_len = strlen(alpn_id_str); if (alpn_id_len > UINT8_MAX) { - syslog(LOG_ERR, "Invalid value '%s' for SvcParam 'alpn'", alpn_id_str); + error("Invalid value '%s' for SvcParam 'alpn'", alpn_id_str); goto err; } @@ -881,7 +880,7 @@ static int parse_dnr_str(char *str, struct interface *iface) uint16_t port; if (sscanf(svc_val_str, "%" SCNu16, &port) != 1) { - syslog(LOG_ERR, "Invalid value '%s' for SvcParam 'port'", svc_val_str); + error("Invalid value '%s' for SvcParam 'port'", svc_val_str); goto err; } @@ -904,7 +903,7 @@ static int parse_dnr_str(char *str, struct interface *iface) case DNR_SVC_OHTTP: if (strlen(svc_val_str) > 0) { - syslog(LOG_ERR, "Invalid value '%s' for SvcParam 'port'", svc_val_str); + error("Invalid value '%s' for SvcParam 'port'", svc_val_str); goto err; } /* fall through */ @@ -927,14 +926,14 @@ static int parse_dnr_str(char *str, struct interface *iface) break; case DNR_SVC_ECH: - syslog(LOG_ERR, "SvcParam 'ech' is not implemented"); + error("SvcParam 'ech' is not implemented"); goto err; case DNR_SVC_IPV4HINT: /* fall through */ case DNR_SVC_IPV6HINT: - syslog(LOG_ERR, "SvcParam '%s' is not allowed", svc_param_key_names[svc_key]); + error("SvcParam '%s' is not allowed", svc_param_key_names[svc_key]); goto err; } } @@ -1066,8 +1065,8 @@ int config_parse_interface(void *data, size_t len, const char *name, bool overwr if (time > 0) iface->dhcp_leasetime = time; else - syslog(LOG_ERR, "Invalid %s value configured for interface '%s'", - iface_attrs[IFACE_ATTR_LEASETIME].name, iface->name); + error("Invalid %s value configured for interface '%s'", + iface_attrs[IFACE_ATTR_LEASETIME].name, iface->name); } @@ -1077,9 +1076,8 @@ int config_parse_interface(void *data, size_t len, const char *name, bool overwr if (time > 0) iface->max_preferred_lifetime = time; else - syslog(LOG_ERR, "Invalid %s value configured for interface '%s'", - iface_attrs[IFACE_ATTR_MAX_PREFERRED_LIFETIME].name, iface->name); - + error("Invalid %s value configured for interface '%s'", + iface_attrs[IFACE_ATTR_MAX_PREFERRED_LIFETIME].name, iface->name); } if ((c = tb[IFACE_ATTR_MAX_VALID_LIFETIME])) { @@ -1088,9 +1086,8 @@ int config_parse_interface(void *data, size_t len, const char *name, bool overwr if (time > 0) iface->max_valid_lifetime = time; else - syslog(LOG_ERR, "Invalid %s value configured for interface '%s'", - iface_attrs[IFACE_ATTR_MAX_VALID_LIFETIME].name, iface->name); - + error("Invalid %s value configured for interface '%s'", + iface_attrs[IFACE_ATTR_MAX_VALID_LIFETIME].name, iface->name); } if ((c = tb[IFACE_ATTR_START])) { @@ -1134,8 +1131,8 @@ int config_parse_interface(void *data, size_t len, const char *name, bool overwr if (iface->ra != MODE_DISABLED) iface->ignore = false; } else - syslog(LOG_ERR, "Invalid %s mode configured for interface '%s'", - iface_attrs[IFACE_ATTR_RA].name, iface->name); + error("Invalid %s mode configured for interface '%s'", + iface_attrs[IFACE_ATTR_RA].name, iface->name); } if ((c = tb[IFACE_ATTR_DHCPV4])) { @@ -1147,8 +1144,8 @@ int config_parse_interface(void *data, size_t len, const char *name, bool overwr iface->ignore = false; } } else - syslog(LOG_ERR, "Invalid %s mode configured for interface %s", - iface_attrs[IFACE_ATTR_DHCPV4].name, iface->name); + error("Invalid %s mode configured for interface %s", + iface_attrs[IFACE_ATTR_DHCPV4].name, iface->name); } if ((c = tb[IFACE_ATTR_DHCPV6])) { @@ -1158,8 +1155,8 @@ int config_parse_interface(void *data, size_t len, const char *name, bool overwr if (iface->dhcpv6 != MODE_DISABLED) iface->ignore = false; } else - syslog(LOG_ERR, "Invalid %s mode configured for interface '%s'", - iface_attrs[IFACE_ATTR_DHCPV6].name, iface->name); + error("Invalid %s mode configured for interface '%s'", + iface_attrs[IFACE_ATTR_DHCPV6].name, iface->name); } if ((c = tb[IFACE_ATTR_NDP])) { @@ -1169,8 +1166,8 @@ int config_parse_interface(void *data, size_t len, const char *name, bool overwr if (iface->ndp != MODE_DISABLED) iface->ignore = false; } else - syslog(LOG_ERR, "Invalid %s mode configured for interface '%s'", - iface_attrs[IFACE_ATTR_NDP].name, iface->name); + error("Invalid %s mode configured for interface '%s'", + iface_attrs[IFACE_ATTR_NDP].name, iface->name); } if ((c = tb[IFACE_ATTR_ROUTER])) { @@ -1191,8 +1188,8 @@ int config_parse_interface(void *data, size_t len, const char *name, bool overwr iface->dhcpv4_router[iface->dhcpv4_router_cnt - 1] = addr4; } else - syslog(LOG_ERR, "Invalid %s value configured for interface '%s'", - iface_attrs[IFACE_ATTR_ROUTER].name, iface->name); + error("Invalid %s value configured for interface '%s'", + iface_attrs[IFACE_ATTR_ROUTER].name, iface->name); } } @@ -1210,9 +1207,8 @@ int config_parse_interface(void *data, size_t len, const char *name, bool overwr if (inet_pton(AF_INET, blobmsg_get_string(cur), &addr4) == 1) { if (addr4.s_addr == INADDR_ANY) { - syslog(LOG_ERR, "Invalid %s value configured for interface '%s'", - iface_attrs[IFACE_ATTR_DNS].name, iface->name); - + error("Invalid %s value configured for interface '%s'", + iface_attrs[IFACE_ATTR_DNS].name, iface->name); continue; } @@ -1224,9 +1220,8 @@ int config_parse_interface(void *data, size_t len, const char *name, bool overwr iface->dhcpv4_dns[iface->dhcpv4_dns_cnt - 1] = addr4; } else if (inet_pton(AF_INET6, blobmsg_get_string(cur), &addr6) == 1) { if (IN6_IS_ADDR_UNSPECIFIED(&addr6)) { - syslog(LOG_ERR, "Invalid %s value configured for interface '%s'", - iface_attrs[IFACE_ATTR_DNS].name, iface->name); - + error("Invalid %s value configured for interface '%s'", + iface_attrs[IFACE_ATTR_DNS].name, iface->name); continue; } @@ -1237,8 +1232,8 @@ int config_parse_interface(void *data, size_t len, const char *name, bool overwr iface->dns[iface->dns_cnt - 1] = addr6; } else - syslog(LOG_ERR, "Invalid %s value configured for interface '%s'", - iface_attrs[IFACE_ATTR_DNS].name, iface->name); + error("Invalid %s value configured for interface '%s'", + iface_attrs[IFACE_ATTR_DNS].name, iface->name); } } @@ -1266,9 +1261,8 @@ int config_parse_interface(void *data, size_t len, const char *name, bool overwr len = dn_comp(domain, buf, sizeof(buf), NULL, NULL); if (len <= 0) { - syslog(LOG_ERR, "Invalid %s value configured for interface '%s'", - iface_attrs[IFACE_ATTR_DOMAIN].name, iface->name); - + error("Invalid %s value configured for interface '%s'", + iface_attrs[IFACE_ATTR_DOMAIN].name, iface->name); continue; } @@ -1307,8 +1301,8 @@ int config_parse_interface(void *data, size_t len, const char *name, bool overwr iface->dhcpv6_pd_min_len = PD_MIN_LEN_MAX; iface->dhcpv6_pd_min_len = pd_min_len; if (pd_min_len >= PD_MIN_LEN_MAX) - syslog(LOG_WARNING, "Clamped invalid %s value configured for interface '%s' to %d", - iface_attrs[IFACE_ATTR_DHCPV6_PD_MIN_LEN].name, iface->name, iface->dhcpv6_pd_min_len); + warn("Clamped invalid %s value configured for interface '%s' to %d", + iface_attrs[IFACE_ATTR_DHCPV6_PD_MIN_LEN].name, iface->name, iface->dhcpv6_pd_min_len); } if ((c = tb[IFACE_ATTR_DHCPV6_NA])) @@ -1326,8 +1320,8 @@ int config_parse_interface(void *data, size_t len, const char *name, bool overwr iface->dhcpv6_hostid_len = hostid_len; if (original_hostid_len != hostid_len) { - syslog(LOG_WARNING, "Clamped invalid %s value configured for interface '%s' to %d", - iface_attrs[IFACE_ATTR_DHCPV6_HOSTID_LEN].name, iface->name, iface->dhcpv6_hostid_len); + warn("Clamped invalid %s value configured for interface '%s' to %d", + iface_attrs[IFACE_ATTR_DHCPV6_HOSTID_LEN].name, iface->name, iface->dhcpv6_hostid_len); } } @@ -1359,8 +1353,8 @@ int config_parse_interface(void *data, size_t len, const char *name, bool overwr iface->ra_flags = 0; if (parse_ra_flags(&iface->ra_flags, c) < 0) - syslog(LOG_ERR, "Invalid %s value configured for interface '%s'", - iface_attrs[IFACE_ATTR_RA_FLAGS].name, iface->name); + error("Invalid %s value configured for interface '%s'", + iface_attrs[IFACE_ATTR_RA_FLAGS].name, iface->name); } if ((c = tb[IFACE_ATTR_RA_REACHABLETIME])) { @@ -1371,8 +1365,8 @@ int config_parse_interface(void *data, size_t len, const char *name, bool overwr */ iface->ra_reachabletime = ra_reachabletime <= AdvReachableTime ? ra_reachabletime : AdvReachableTime; if(ra_reachabletime > AdvReachableTime) - syslog(LOG_WARNING, "Clamped invalid %s value configured for interface '%s' to %d", - iface_attrs[IFACE_ATTR_RA_REACHABLETIME].name, iface->name, iface->ra_reachabletime); + warn("Clamped invalid %s value configured for interface '%s' to %d", + iface_attrs[IFACE_ATTR_RA_REACHABLETIME].name, iface->name, iface->ra_reachabletime); } if ((c = tb[IFACE_ATTR_RA_RETRANSTIME])) { @@ -1380,8 +1374,8 @@ int config_parse_interface(void *data, size_t len, const char *name, bool overwr iface->ra_retranstime = ra_retranstime <= RETRANS_TIMER_MAX ? ra_retranstime : RETRANS_TIMER_MAX; if (ra_retranstime > RETRANS_TIMER_MAX) - syslog(LOG_WARNING, "Clamped invalid %s value configured for interface '%s' to %d", - iface_attrs[IFACE_ATTR_RA_RETRANSTIME].name, iface->name, iface->ra_retranstime); + warn("Clamped invalid %s value configured for interface '%s' to %d", + iface_attrs[IFACE_ATTR_RA_RETRANSTIME].name, iface->name, iface->ra_retranstime); } if ((c = tb[IFACE_ATTR_RA_HOPLIMIT])) { @@ -1390,8 +1384,8 @@ int config_parse_interface(void *data, size_t len, const char *name, bool overwr /* RFC4861 §6.2.1 : AdvCurHopLimit */ iface->ra_hoplimit = ra_hoplimit <= AdvCurHopLimit ? ra_hoplimit : AdvCurHopLimit; if(ra_hoplimit > AdvCurHopLimit) - syslog(LOG_WARNING, "Clamped invalid %s value configured for interface '%s' to %d", - iface_attrs[IFACE_ATTR_RA_HOPLIMIT].name, iface->name, iface->ra_hoplimit); + warn("Clamped invalid %s value configured for interface '%s' to %d", + iface_attrs[IFACE_ATTR_RA_HOPLIMIT].name, iface->name, iface->ra_hoplimit); } @@ -1405,8 +1399,8 @@ int config_parse_interface(void *data, size_t len, const char *name, bool overwr iface->ra_mtu = ra_mtu; if (original_ra_mtu != ra_mtu) { - syslog(LOG_WARNING, "Clamped invalid %s value configured for interface '%s' to %d", - iface_attrs[IFACE_ATTR_RA_MTU].name, iface->name, iface->ra_mtu); + warn("Clamped invalid %s value configured for interface '%s' to %d", + iface_attrs[IFACE_ATTR_RA_MTU].name, iface->name, iface->ra_mtu); } } @@ -1476,8 +1470,8 @@ int config_parse_interface(void *data, size_t len, const char *name, bool overwr continue; if (parse_dnr_str(blobmsg_get_string(cur), iface)) - syslog(LOG_ERR, "Invalid %s value configured for interface '%s'", - iface_attrs[IFACE_ATTR_DNR].name, iface->name); + error("Invalid %s value configured for interface '%s'", + iface_attrs[IFACE_ATTR_DNR].name, iface->name); } } @@ -1520,8 +1514,8 @@ int config_parse_interface(void *data, size_t len, const char *name, bool overwr iface->pref64_prefix[2] = 0; break; default: - syslog(LOG_WARNING, "Invalid PREF64 prefix size (%d), " - "ignoring ra_pref64 option!", iface->pref64_length); + warn("Invalid PREF64 prefix size (%d), ignoring ra_pref64 option!", + iface->pref64_length); iface->pref64_length = 0; } } @@ -1536,8 +1530,8 @@ int config_parse_interface(void *data, size_t len, const char *name, bool overwr else if (!strcmp(prio, "medium") || !strcmp(prio, "default")) iface->route_preference = 0; else - syslog(LOG_ERR, "Invalid %s mode configured for interface '%s'", - iface_attrs[IFACE_ATTR_RA_PREFERENCE].name, iface->name); + error("Invalid %s mode configured for interface '%s'", + iface_attrs[IFACE_ATTR_RA_PREFERENCE].name, iface->name); } if ((c = tb[IFACE_ATTR_PD_MANAGER])) @@ -1546,8 +1540,8 @@ int config_parse_interface(void *data, size_t len, const char *name, bool overwr if ((c = tb[IFACE_ATTR_PD_CER]) && inet_pton(AF_INET6, blobmsg_get_string(c), &iface->dhcpv6_pd_cer) < 1) - syslog(LOG_ERR, "Invalid %s value configured for interface '%s'", - iface_attrs[IFACE_ATTR_PD_CER].name, iface->name); + error("Invalid %s value configured for interface '%s'", + iface_attrs[IFACE_ATTR_PD_CER].name, iface->name); if ((c = tb[IFACE_ATTR_NDPROXY_ROUTING])) iface->learn_routes = blobmsg_get_bool(c); @@ -1813,7 +1807,7 @@ struct lease *config_find_lease_by_ipaddr(const uint32_t ipaddr) void reload_services(struct interface *iface) { if (iface->ifflags & IFF_RUNNING) { - syslog(LOG_DEBUG, "Enabling services with %s running", iface->ifname); + debug("Enabling services with %s running", iface->ifname); router_setup_interface(iface, iface->ra != MODE_DISABLED); dhcpv6_setup_interface(iface, iface->dhcpv6 != MODE_DISABLED); ndp_setup_interface(iface, iface->ndp != MODE_DISABLED); @@ -1821,7 +1815,7 @@ void reload_services(struct interface *iface) dhcpv4_setup_interface(iface, iface->dhcpv4 != MODE_DISABLED); #endif } else { - syslog(LOG_DEBUG, "Disabling services with %s not running", iface->ifname); + debug("Disabling services with %s not running", iface->ifname); router_setup_interface(iface, false); dhcpv6_setup_interface(iface, false); ndp_setup_interface(iface, false); @@ -1923,10 +1917,9 @@ static json_object *config_load_ra_pio_json(struct interface *iface) close(fd); if (!json) - syslog(LOG_ERR, - "rfc9096: %s: json read error %s", - iface->ifname, - json_util_get_last_err()); + error("rfc9096: %s: json read error %s", + iface->ifname, + json_util_get_last_err()); return json; } @@ -1989,12 +1982,11 @@ void config_load_ra_pio(struct interface *iface) inet_pton(AF_INET6, pio_str, &pio->prefix); pio->length = pio_len; pio->lifetime = pio_lt; - syslog(LOG_INFO, - "rfc9096: %s: load %s/%u (%u)", - iface->ifname, - pio_str, - pio_len, - ra_pio_lifetime(pio, now)); + info("rfc9096: %s: load %s/%u (%u)", + iface->ifname, + pio_str, + pio_len, + ra_pio_lifetime(pio, now)); iface->pio_cnt++; } @@ -2024,18 +2016,16 @@ static void config_save_ra_pio_json(struct interface *iface, struct json_object O_CREAT | O_TRUNC | O_WRONLY | O_CLOEXEC, 0644); if (fd < 0) { - syslog(LOG_ERR, - "rfc9096: %s: error %m creating temporary json file", - iface->ifname); + error("rfc9096: %s: error %m creating temporary json file", + iface->ifname); return; } ret = json_object_to_fd(fd, json, JSON_C_TO_STRING_PLAIN); if (ret) { - syslog(LOG_ERR, - "rfc9096: %s: json write error %s", - iface->ifname, - json_util_get_last_err()); + error("rfc9096: %s: json write error %s", + iface->ifname, + json_util_get_last_err()); close(fd); unlinkat(config.ra_piofolder_fd, tmp_piofile, 0); return; @@ -2043,10 +2033,9 @@ static void config_save_ra_pio_json(struct interface *iface, struct json_object ret = fsync(fd); if (ret) { - syslog(LOG_ERR, - "rfc9096: %s: error %m syncing %s", - iface->ifname, - tmp_piofile); + error("rfc9096: %s: error %m syncing %s", + iface->ifname, + tmp_piofile); close(fd); unlinkat(config.ra_piofolder_fd, tmp_piofile, 0); return; @@ -2054,10 +2043,9 @@ static void config_save_ra_pio_json(struct interface *iface, struct json_object ret = close(fd); if (ret) { - syslog(LOG_ERR, - "rfc9096: %s: error %m closing %s", - iface->ifname, - tmp_piofile); + error("rfc9096: %s: error %m closing %s", + iface->ifname, + tmp_piofile); unlinkat(config.ra_piofolder_fd, tmp_piofile, 0); return; } @@ -2067,20 +2055,17 @@ static void config_save_ra_pio_json(struct interface *iface, struct json_object config.ra_piofolder_fd, iface->ifname); if (ret) { - syslog(LOG_ERR, - "rfc9096: %s: error %m renaming piofile: %s -> %s", - iface->ifname, - tmp_piofile, - iface->ifname); + error("rfc9096: %s: error %m renaming piofile: %s -> %s", + iface->ifname, + tmp_piofile, + iface->ifname); close(fd); unlinkat(config.ra_piofolder_fd, tmp_piofile, 0); return; } iface->pio_update = false; - syslog(LOG_WARNING, - "rfc9096: %s: piofile updated", - iface->ifname); + warn("rfc9096: %s: piofile updated", iface->ifname); } void config_save_ra_pio(struct interface *iface) @@ -2219,7 +2204,7 @@ void odhcpd_reload(void) close(config.ra_piofolder_fd); config.ra_piofolder_fd = open(path, O_PATH | O_DIRECTORY | O_CLOEXEC); if (config.ra_piofolder_fd < 0) - syslog(LOG_ERR, "Unable to open piofolder '%s': %m", path); + error("Unable to open piofolder '%s': %m", path); } vlist_flush(&leases); diff --git a/src/dhcpv4.c b/src/dhcpv4.c index bdcd8e8..dcb2373 100644 --- a/src/dhcpv4.c +++ b/src/dhcpv4.c @@ -228,11 +228,11 @@ static void dhcpv4_fr_send(struct dhcp_assignment *a) if (sendto(iface->dhcpv4_event.uloop.fd, &fr_msg, PACKET_SIZE(&fr_msg, cursor), MSG_DONTWAIT, (struct sockaddr*)&dest, sizeof(dest)) < 0) - syslog(LOG_ERR, "Failed to send %s to %s - %s: %m", dhcpv4_msg_to_string(msg), - odhcpd_print_mac(a->hwaddr, sizeof(a->hwaddr)), inet_ntoa(dest.sin_addr)); + error("Failed to send %s to %s - %s: %m", dhcpv4_msg_to_string(msg), + odhcpd_print_mac(a->hwaddr, sizeof(a->hwaddr)), inet_ntoa(dest.sin_addr)); else - syslog(LOG_DEBUG, "Sent %s to %s - %s", dhcpv4_msg_to_string(msg), - odhcpd_print_mac(a->hwaddr, sizeof(a->hwaddr)), inet_ntoa(dest.sin_addr)); + debug("Sent %s to %s - %s", dhcpv4_msg_to_string(msg), + odhcpd_print_mac(a->hwaddr, sizeof(a->hwaddr)), inet_ntoa(dest.sin_addr)); } static void dhcpv4_fr_stop(struct dhcp_assignment *a) @@ -331,8 +331,8 @@ static bool dhcpv4_assign(struct interface *iface, struct dhcp_assignment *a, a, a->addr); if (assigned) - syslog(LOG_DEBUG, "Assigning static IP: %s", - inet_ntop(AF_INET, &a->addr, ipv4_str, sizeof(ipv4_str))); + debug("Assigning static IP: %s", + inet_ntop(AF_INET, &a->addr, ipv4_str, sizeof(ipv4_str))); return assigned; } @@ -344,8 +344,8 @@ static bool dhcpv4_assign(struct interface *iface, struct dhcp_assignment *a, a, raddr); if (assigned) { - syslog(LOG_DEBUG, "Assigning the IP the client asked for: %s", - inet_ntop(AF_INET, &a->addr, ipv4_str, sizeof(ipv4_str))); + debug("Assigning the IP the client asked for: %s", + inet_ntop(AF_INET, &a->addr, ipv4_str, sizeof(ipv4_str))); return true; } } @@ -370,15 +370,15 @@ static bool dhcpv4_assign(struct interface *iface, struct dhcp_assignment *a, a, n_try); if (assigned) { - syslog(LOG_DEBUG, "Assigning mapped IP: %s (try %u of %u)", - inet_ntop(AF_INET, &a->addr, ipv4_str, sizeof(ipv4_str)), - i + 1, count); + debug("Assigning mapped IP: %s (try %u of %u)", + inet_ntop(AF_INET, &a->addr, ipv4_str, sizeof(ipv4_str)), + i + 1, count); return true; } } - syslog(LOG_NOTICE, "Can't assign any IP address -> address space is full"); + notice("Can't assign any IP address -> address space is full"); return false; } @@ -436,8 +436,8 @@ dhcpv4_lease(struct interface *iface, enum dhcpv4_msg msg, const uint8_t *mac, /* Create new binding */ a = alloc_assignment(0); if (!a) { - syslog(LOG_WARNING, "Failed to alloc assignment on interface %s", - iface->ifname); + warn("Failed to alloc assignment on interface %s", + iface->ifname); return NULL; } memcpy(a->hwaddr, mac, sizeof(a->hwaddr)); @@ -573,10 +573,10 @@ void dhcpv4_handle_msg(void *addr, void *data, size_t len, req->op != DHCPV4_OP_BOOTREQUEST || req->hlen != ETH_ALEN) return; - syslog(LOG_DEBUG, "Got DHCPv4 request on %s", iface->name); + debug("Got DHCPv4 request on %s", iface->name); if (!iface->dhcpv4_start_ip.s_addr && !iface->dhcpv4_end_ip.s_addr) { - syslog(LOG_WARNING, "No DHCP range available on %s", iface->name); + warn("No DHCP range available on %s", iface->name); return; } @@ -703,8 +703,8 @@ void dhcpv4_handle_msg(void *addr, void *data, size_t len, req->ciaddr.s_addr = INADDR_ANY; } - syslog(LOG_INFO, "Received %s from %s on %s", dhcpv4_msg_to_string(reqmsg), - odhcpd_print_mac(req->chaddr, req->hlen), iface->name); + info("Received %s from %s on %s", dhcpv4_msg_to_string(reqmsg), + odhcpd_print_mac(req->chaddr, req->hlen), iface->name); if (reqmsg == DHCPV4_MSG_DECLINE || reqmsg == DHCPV4_MSG_RELEASE) return; @@ -910,23 +910,23 @@ void dhcpv4_handle_msg(void *addr, void *data, size_t len, memcpy(arp.arp_dev, iface->ifname, sizeof(arp.arp_dev)); if (ioctl(sock, SIOCSARP, &arp) < 0) - syslog(LOG_ERR, "ioctl(SIOCSARP): %m"); + error("ioctl(SIOCSARP): %m"); } } if (send_reply(&reply, PACKET_SIZE(&reply, cursor), (struct sockaddr*)&dest, sizeof(dest), opaque) < 0) - syslog(LOG_ERR, "Failed to send %s to %s - %s: %m", - dhcpv4_msg_to_string(msg), - dest.sin_addr.s_addr == INADDR_BROADCAST ? - "ff:ff:ff:ff:ff:ff": odhcpd_print_mac(req->chaddr, req->hlen), - inet_ntoa(dest.sin_addr)); + error("Failed to send %s to %s - %s: %m", + dhcpv4_msg_to_string(msg), + dest.sin_addr.s_addr == INADDR_BROADCAST ? + "ff:ff:ff:ff:ff:ff": odhcpd_print_mac(req->chaddr, req->hlen), + inet_ntoa(dest.sin_addr)); else - syslog(LOG_DEBUG, "Sent %s to %s - %s", - dhcpv4_msg_to_string(msg), - dest.sin_addr.s_addr == INADDR_BROADCAST ? - "ff:ff:ff:ff:ff:ff": odhcpd_print_mac(req->chaddr, req->hlen), - inet_ntoa(dest.sin_addr)); + debug("Sent %s to %s - %s", + dhcpv4_msg_to_string(msg), + dest.sin_addr.s_addr == INADDR_BROADCAST ? + "ff:ff:ff:ff:ff:ff": odhcpd_print_mac(req->chaddr, req->hlen), + inet_ntoa(dest.sin_addr)); if (msg == DHCPV4_MSG_ACK && a) ubus_bcast_dhcp_event("dhcp.ack", req->chaddr, @@ -955,12 +955,12 @@ static int dhcpv4_setup_addresses(struct interface *iface) if (iface->dhcpv4_start.s_addr & htonl(0xffff0000) || iface->dhcpv4_end.s_addr & htonl(0xffff0000) || ntohl(iface->dhcpv4_start.s_addr) > ntohl(iface->dhcpv4_end.s_addr)) { - syslog(LOG_WARNING, "Invalid DHCP range for %s", iface->name); + warn("Invalid DHCP range for %s", iface->name); return -1; } if (!iface->addr4_len) { - syslog(LOG_WARNING, "No network(s) available on %s", iface->name); + warn("No network(s) available on %s", iface->name); return -1; } @@ -991,7 +991,8 @@ static int dhcpv4_setup_addresses(struct interface *iface) /* Don't allocate IP range for subnets smaller than /28 */ if (iface->addr4[0].prefix > MAX_PREFIX_LEN) { - syslog(LOG_WARNING, "Auto allocation of DHCP range fails on %s (prefix length must be < %d).", iface->name, MAX_PREFIX_LEN + 1); + warn("Auto allocation of DHCP range fails on %s (prefix length must be < %d).", + iface->name, MAX_PREFIX_LEN + 1); return -1; } @@ -1046,7 +1047,7 @@ int dhcpv4_setup_interface(struct interface *iface, bool enable) iface->dhcpv4_event.uloop.fd = socket(AF_INET, SOCK_DGRAM | SOCK_CLOEXEC, IPPROTO_UDP); if (iface->dhcpv4_event.uloop.fd < 0) { - syslog(LOG_ERR, "socket(AF_INET): %m"); + error("socket(AF_INET): %m"); ret = -1; goto out; } @@ -1054,21 +1055,21 @@ int dhcpv4_setup_interface(struct interface *iface, bool enable) /* Basic IPv4 configuration */ if (setsockopt(iface->dhcpv4_event.uloop.fd, SOL_SOCKET, SO_REUSEADDR, &val, sizeof(val)) < 0) { - syslog(LOG_ERR, "setsockopt(SO_REUSEADDR): %m"); + error("setsockopt(SO_REUSEADDR): %m"); ret = -1; goto out; } if (setsockopt(iface->dhcpv4_event.uloop.fd, SOL_SOCKET, SO_BROADCAST, &val, sizeof(val)) < 0) { - syslog(LOG_ERR, "setsockopt(SO_BROADCAST): %m"); + error("setsockopt(SO_BROADCAST): %m"); ret = -1; goto out; } if (setsockopt(iface->dhcpv4_event.uloop.fd, IPPROTO_IP, IP_PKTINFO, &val, sizeof(val)) < 0) { - syslog(LOG_ERR, "setsockopt(IP_PKTINFO): %m"); + error("setsockopt(IP_PKTINFO): %m"); ret = -1; goto out; } @@ -1076,7 +1077,7 @@ int dhcpv4_setup_interface(struct interface *iface, bool enable) val = IPTOS_PREC_INTERNETCONTROL; if (setsockopt(iface->dhcpv4_event.uloop.fd, IPPROTO_IP, IP_TOS, &val, sizeof(val)) < 0) { - syslog(LOG_ERR, "setsockopt(IP_TOS): %m"); + error("setsockopt(IP_TOS): %m"); ret = -1; goto out; } @@ -1084,21 +1085,21 @@ int dhcpv4_setup_interface(struct interface *iface, bool enable) val = IP_PMTUDISC_DONT; if (setsockopt(iface->dhcpv4_event.uloop.fd, IPPROTO_IP, IP_MTU_DISCOVER, &val, sizeof(val)) < 0) { - syslog(LOG_ERR, "setsockopt(IP_MTU_DISCOVER): %m"); + error("setsockopt(IP_MTU_DISCOVER): %m"); ret = -1; goto out; } if (setsockopt(iface->dhcpv4_event.uloop.fd, SOL_SOCKET, SO_BINDTODEVICE, iface->ifname, strlen(iface->ifname)) < 0) { - syslog(LOG_ERR, "setsockopt(SO_BINDTODEVICE): %m"); + error("setsockopt(SO_BINDTODEVICE): %m"); ret = -1; goto out; } if (bind(iface->dhcpv4_event.uloop.fd, (struct sockaddr *)&bind_addr, sizeof(bind_addr)) < 0) { - syslog(LOG_ERR, "bind(): %m"); + error("bind(): %m"); ret = -1; goto out; } @@ -1147,7 +1148,7 @@ static void dhcpv4_addrlist_change(struct interface *iface) a = list_first_entry(&iface->dhcpv4_fr_ips, struct odhcpd_ref_ip, head); if (netlink_setup_addr(&a->addr, iface->ifindex, false, true)) { - syslog(LOG_WARNING, "Failed to add ip address on %s", iface->name); + warn("Failed to add ip address on %s", iface->name); return; } diff --git a/src/dhcpv6-ia.c b/src/dhcpv6-ia.c index 1bdcfd3..803d377 100644 --- a/src/dhcpv6-ia.c +++ b/src/dhcpv6-ia.c @@ -73,7 +73,7 @@ int dhcpv6_ia_setup_interface(struct interface *iface, bool enable) border = alloc_assignment(0); if (!border) { - syslog(LOG_WARNING, "Failed to alloc border on %s", iface->name); + warn("Failed to alloc border on %s", iface->name); return -1; } @@ -235,9 +235,9 @@ void dhcpv6_ia_enum_addrs(struct interface *iface, struct dhcp_assignment *c, /* Filter Out Prefixes */ if (ADDR_MATCH_PIO_FILTER(&addrs[i], iface)) { char addrbuf[INET6_ADDRSTRLEN]; - syslog(LOG_INFO, "Address %s filtered out on %s", - inet_ntop(AF_INET6, &addrs[i].addr.in6, addrbuf, sizeof(addrbuf)), - iface->name); + info("Address %s filtered out on %s", + inet_ntop(AF_INET6, &addrs[i].addr.in6, addrbuf, sizeof(addrbuf)), + iface->name); continue; } @@ -755,7 +755,7 @@ static bool assign_pd(struct interface *iface, struct dhcp_assignment *assign) /* Wait initial period of up to 250ms for immediate assignment */ if (poll(&pfd, 1, 250) < 0) { - syslog(LOG_ERR, "poll(): %m"); + error("poll(): %m"); return false; } @@ -1074,9 +1074,9 @@ static size_t build_ia(uint8_t *buf, size_t buflen, uint16_t status, /* Filter Out Prefixes */ if (ADDR_MATCH_PIO_FILTER(&addrs[i], iface)) { char addrbuf[INET6_ADDRSTRLEN]; - syslog(LOG_INFO, "Address %s filtered out on %s", - inet_ntop(AF_INET6, &addrs[i].addr.in6, addrbuf, sizeof(addrbuf)), - iface->name); + info("Address %s filtered out on %s", + inet_ntop(AF_INET6, &addrs[i].addr.in6, addrbuf, sizeof(addrbuf)), + iface->name); continue; } @@ -1338,8 +1338,8 @@ static void dhcpv6_log(uint8_t msgtype, struct interface *iface, time_t now, dhcpv6_ia_enum_addrs(iface, a, now, dhcpv6_log_ia_addr, &ctxt); } - syslog(LOG_INFO, "DHCPV6 %s %s from %s on %s: %s %s", type, (is_pd) ? "IA_PD" : "IA_NA", - duidbuf, iface->name, status, leasebuf); + info("DHCPV6 %s %s from %s on %s: %s %s", type, (is_pd) ? "IA_PD" : "IA_NA", + duidbuf, iface->name, status, leasebuf); } static bool dhcpv6_ia_on_link(const struct dhcpv6_ia_hdr *ia, struct dhcp_assignment *a, @@ -1484,8 +1484,8 @@ ssize_t dhcpv6_ia_handle_IAs(uint8_t *buf, size_t buflen, struct interface *ifac * 1/16 of our total address space. */ if (iface->dhcpv6_pd_min_len && reqlen < iface->dhcpv6_pd_min_len) { - syslog(LOG_INFO, "clamping requested PD from %d to %d", - reqlen, iface->dhcpv6_pd_min_len); + info("clamping requested PD from %d to %d", reqlen, + iface->dhcpv6_pd_min_len); reqlen = iface->dhcpv6_pd_min_len; } } else if (is_na) { diff --git a/src/dhcpv6-pxe.c b/src/dhcpv6-pxe.c index 7169602..e72a317 100644 --- a/src/dhcpv6-pxe.c +++ b/src/dhcpv6-pxe.c @@ -63,7 +63,7 @@ void ipv6_pxe_serve_boot_url(uint16_t arch, struct iovec* iov) { else { iov->iov_base = (void*)&(entry->bootfile_url); iov->iov_len = 4 + ntohs(entry->bootfile_url.len); - syslog(LOG_INFO, "Serve IPv6 PxE, arch = %d, url = %s", arch, entry->bootfile_url.payload); + info("Serve IPv6 PxE, arch = %d, url = %s", arch, entry->bootfile_url.payload); } } @@ -79,14 +79,13 @@ void ipv6_pxe_dump(void) { } if (count) { - syslog(LOG_INFO, "IPv6 PxE URLs:\n"); + info("IPv6 PxE URLs:\n"); - list_for_each_entry(entry, &ipv6_pxe_list, list) { - syslog(LOG_INFO, " arch %04d = %s\n", entry->arch, entry->bootfile_url.payload); - } + list_for_each_entry(entry, &ipv6_pxe_list, list) + info(" arch %04d = %s\n", entry->arch, entry->bootfile_url.payload); if (ipv6_pxe_default) - syslog(LOG_INFO, " Default = %s\n", ipv6_pxe_default->bootfile_url.payload); + info(" Default = %s\n", ipv6_pxe_default->bootfile_url.payload); } } diff --git a/src/dhcpv6.c b/src/dhcpv6.c index 3c0289d..73ce0b3 100644 --- a/src/dhcpv6.c +++ b/src/dhcpv6.c @@ -67,7 +67,7 @@ int dhcpv6_setup_interface(struct interface *iface, bool enable) iface->dhcpv6_event.uloop.fd = socket(AF_INET6, SOCK_DGRAM | SOCK_CLOEXEC, IPPROTO_UDP); if (iface->dhcpv6_event.uloop.fd < 0) { - syslog(LOG_ERR, "socket(AF_INET6): %m"); + error("socket(AF_INET6): %m"); ret = -1; goto out; } @@ -75,28 +75,28 @@ int dhcpv6_setup_interface(struct interface *iface, bool enable) /* Basic IPv6 configuration */ if (setsockopt(iface->dhcpv6_event.uloop.fd, SOL_SOCKET, SO_BINDTODEVICE, iface->ifname, strlen(iface->ifname)) < 0) { - syslog(LOG_ERR, "setsockopt(SO_BINDTODEVICE): %m"); + error("setsockopt(SO_BINDTODEVICE): %m"); ret = -1; goto out; } if (setsockopt(iface->dhcpv6_event.uloop.fd, IPPROTO_IPV6, IPV6_V6ONLY, &val, sizeof(val)) < 0) { - syslog(LOG_ERR, "setsockopt(IPV6_V6ONLY): %m"); + error("setsockopt(IPV6_V6ONLY): %m"); ret = -1; goto out; } if (setsockopt(iface->dhcpv6_event.uloop.fd, SOL_SOCKET, SO_REUSEADDR, &val, sizeof(val)) < 0) { - syslog(LOG_ERR, "setsockopt(SO_REUSEADDR): %m"); + error("setsockopt(SO_REUSEADDR): %m"); ret = -1; goto out; } if (setsockopt(iface->dhcpv6_event.uloop.fd, IPPROTO_IPV6, IPV6_RECVPKTINFO, &val, sizeof(val)) < 0) { - syslog(LOG_ERR, "setsockopt(IPV6_RECVPKTINFO): %m"); + error("setsockopt(IPV6_RECVPKTINFO): %m"); ret = -1; goto out; } @@ -104,7 +104,7 @@ int dhcpv6_setup_interface(struct interface *iface, bool enable) val = DHCPV6_HOP_COUNT_LIMIT; if (setsockopt(iface->dhcpv6_event.uloop.fd, IPPROTO_IPV6, IPV6_MULTICAST_HOPS, &val, sizeof(val)) < 0) { - syslog(LOG_ERR, "setsockopt(IPV6_MULTICAST_HOPS): %m"); + error("setsockopt(IPV6_MULTICAST_HOPS): %m"); ret = -1; goto out; } @@ -112,14 +112,14 @@ int dhcpv6_setup_interface(struct interface *iface, bool enable) val = 0; if (setsockopt(iface->dhcpv6_event.uloop.fd, IPPROTO_IPV6, IPV6_MULTICAST_LOOP, &val, sizeof(val)) < 0) { - syslog(LOG_ERR, "setsockopt(IPV6_MULTICAST_LOOP): %m"); + error("setsockopt(IPV6_MULTICAST_LOOP): %m"); ret = -1; goto out; } if (bind(iface->dhcpv6_event.uloop.fd, (struct sockaddr*)&bind_addr, sizeof(bind_addr)) < 0) { - syslog(LOG_ERR, "bind(): %m"); + error("bind(): %m"); ret = -1; goto out; } @@ -130,7 +130,7 @@ int dhcpv6_setup_interface(struct interface *iface, bool enable) if (setsockopt(iface->dhcpv6_event.uloop.fd, IPPROTO_IPV6, IPV6_ADD_MEMBERSHIP, &mreq, sizeof(mreq)) < 0) { - syslog(LOG_ERR, "setsockopt(IPV6_ADD_MEMBERSHIP): %m"); + error("setsockopt(IPV6_ADD_MEMBERSHIP): %m"); ret = -1; goto out; } @@ -142,7 +142,7 @@ int dhcpv6_setup_interface(struct interface *iface, bool enable) if (setsockopt(iface->dhcpv6_event.uloop.fd, IPPROTO_IPV6, IPV6_ADD_MEMBERSHIP, &mreq, sizeof(mreq)) < 0) { - syslog(LOG_ERR, "setsockopt(IPV6_ADD_MEMBERSHIP): %m"); + error("setsockopt(IPV6_ADD_MEMBERSHIP): %m"); ret = -1; goto out; } @@ -260,7 +260,7 @@ static int send_reply(_unused const void *buf, size_t len, struct dhcpv4_msg_data *reply = opaque; if (len > reply->maxsize) { - syslog(LOG_ERR, "4o6: reply too large, %zu > %zu", len, reply->maxsize); + error("4o6: reply too large, %zu > %zu", len, reply->maxsize); reply->len = -1; } else { memcpy(reply->msg, buf, len); @@ -290,7 +290,7 @@ static ssize_t dhcpv6_4o6_query(uint8_t *buf, size_t buflen, } if (!msgv4_data || msgv4_len == 0) { - syslog(LOG_ERR, "4o6: missing DHCPv4 message option (%d)", DHCPV6_OPT_DHCPV4_MSG); + error("4o6: missing DHCPv4 message option (%d)", DHCPV6_OPT_DHCPV4_MSG); return -1; } @@ -318,7 +318,7 @@ static void handle_client_request(void *addr, void *data, size_t len, if (len < sizeof(*hdr)) return; - syslog(LOG_DEBUG, "Got a DHCPv6-request on %s", iface->name); + debug("Got a DHCPv6-request on %s", iface->name); /* Construct reply message */ struct __attribute__((packed)) { @@ -709,7 +709,7 @@ static void handle_client_request(void *addr, void *data, size_t len, msglen = dhcpv6_4o6_query(msg_opt->msg, sizeof(pdbuf) - sizeof(*msg_opt) + 1, iface, addr, (const void *)hdr, opts_end); if (msglen <= 0) { - syslog(LOG_ERR, "4o6: query failed"); + error("4o6: query failed"); return; } @@ -741,7 +741,7 @@ static void handle_client_request(void *addr, void *data, size_t len, iov[IOV_DNR].iov_len + iov[IOV_BOOTFILE_URL].iov_len - (4 + opts_end - opts)); - syslog(LOG_DEBUG, "Sending a DHCPv6-%s on %s", iov[IOV_NESTED].iov_len ? "relay-reply" : "reply", iface->name); + debug("Sending a DHCPv6-%s on %s", iov[IOV_NESTED].iov_len ? "relay-reply" : "reply", iface->name); odhcpd_send(iface->dhcpv6_event.uloop.fd, addr, iov, ARRAY_SIZE(iov), iface); } @@ -776,7 +776,7 @@ static void relay_server_response(uint8_t *data, size_t len) /* Relay DHCPv6 reply from server to client */ struct dhcpv6_relay_header *h = (void*)data; - syslog(LOG_DEBUG, "Got a DHCPv6-relay-reply"); + debug("Got a DHCPv6-relay-reply"); if (len < sizeof(*h) || h->msg_type != DHCPV6_MSG_RELAY_REPL) return; @@ -846,7 +846,7 @@ static void relay_server_response(uint8_t *data, size_t len) struct iovec iov = {payload_data, payload_len}; - syslog(LOG_DEBUG, "Sending a DHCPv6-reply on %s", iface->name); + debug("Sending a DHCPv6-reply on %s", iface->name); odhcpd_send(iface->dhcpv6_event.uloop.fd, &target, &iov, 1, iface); } @@ -897,7 +897,7 @@ static void relay_client_request(struct sockaddr_in6 *source, h->msg_type == DHCPV6_MSG_ADVERTISE) return; /* Invalid message types for client */ - syslog(LOG_DEBUG, "Got a DHCPv6-request on %s", iface->name); + debug("Got a DHCPv6-request on %s", iface->name); if (h->msg_type == DHCPV6_MSG_RELAY_FORW) { /* handle relay-forward */ if (h->hop_count >= DHCPV6_HOP_COUNT_LIMIT) @@ -938,7 +938,7 @@ static void relay_client_request(struct sockaddr_in6 *source, ip = NULL; } - syslog(LOG_DEBUG, "Sending a DHCPv6-relay-forward on %s", c->name); + debug("Sending a DHCPv6-relay-forward on %s", c->name); odhcpd_send(c->dhcpv6_event.uloop.fd, &s, iov, 2, c); } diff --git a/src/ndp.c b/src/ndp.c index 89b20e6..25cc831 100644 --- a/src/ndp.c +++ b/src/ndp.c @@ -58,7 +58,7 @@ int ndp_init(void) int ret = 0; if (netlink_add_netevent_handler(&ndp_netevent_handler) < 0) { - syslog(LOG_ERR, "Failed to add ndp netevent handler"); + error("Failed to add ndp netevent handler"); ret = -1; } @@ -108,21 +108,21 @@ int ndp_setup_interface(struct interface *iface, bool enable) /* Open ICMPv6 socket */ iface->ndp_ping_fd = socket(AF_INET6, SOCK_RAW | SOCK_CLOEXEC, IPPROTO_ICMPV6); if (iface->ndp_ping_fd < 0) { - syslog(LOG_ERR, "socket(AF_INET6): %m"); + error("socket(AF_INET6): %m"); ret = -1; goto out; } if (setsockopt(iface->ndp_ping_fd, SOL_SOCKET, SO_BINDTODEVICE, iface->ifname, strlen(iface->ifname)) < 0) { - syslog(LOG_ERR, "setsockopt(SO_BINDTODEVICE): %m"); + error("setsockopt(SO_BINDTODEVICE): %m"); ret = -1; goto out; } if (setsockopt(iface->ndp_ping_fd, IPPROTO_RAW, IPV6_CHECKSUM, &val, sizeof(val)) < 0) { - syslog(LOG_ERR, "setsockopt(IPV6_CHECKSUM): %m"); + error("setsockopt(IPV6_CHECKSUM): %m"); ret = -1; goto out; } @@ -131,14 +131,14 @@ int ndp_setup_interface(struct interface *iface, bool enable) val = 255; if (setsockopt(iface->ndp_ping_fd, IPPROTO_IPV6, IPV6_MULTICAST_HOPS, &val, sizeof(val)) < 0) { - syslog(LOG_ERR, "setsockopt(IPV6_MULTICAST_HOPS): %m"); + error("setsockopt(IPV6_MULTICAST_HOPS): %m"); ret = -1; goto out; } if (setsockopt(iface->ndp_ping_fd, IPPROTO_IPV6, IPV6_UNICAST_HOPS, &val, sizeof(val)) < 0) { - syslog(LOG_ERR, "setsockopt(IPV6_UNICAST_HOPS): %m"); + error("setsockopt(IPV6_UNICAST_HOPS): %m"); ret = -1; goto out; } @@ -147,7 +147,7 @@ int ndp_setup_interface(struct interface *iface, bool enable) ICMP6_FILTER_SETBLOCKALL(&filt); if (setsockopt(iface->ndp_ping_fd, IPPROTO_ICMPV6, ICMP6_FILTER, &filt, sizeof(filt)) < 0) { - syslog(LOG_ERR, "setsockopt(ICMP6_FILTER): %m"); + error("setsockopt(ICMP6_FILTER): %m"); ret = -1; goto out; } @@ -155,7 +155,7 @@ int ndp_setup_interface(struct interface *iface, bool enable) iface->ndp_event.uloop.fd = socket(AF_PACKET, SOCK_DGRAM | SOCK_CLOEXEC, htons(ETH_P_IPV6)); if (iface->ndp_event.uloop.fd < 0) { - syslog(LOG_ERR, "socket(AF_PACKET): %m"); + error("socket(AF_PACKET): %m"); ret = -1; goto out; } @@ -164,7 +164,7 @@ int ndp_setup_interface(struct interface *iface, bool enable) int pktt = 1 << PACKET_MULTICAST; if (setsockopt(iface->ndp_event.uloop.fd, SOL_PACKET, PACKET_RECV_TYPE, &pktt, sizeof(pktt)) < 0) { - syslog(LOG_ERR, "setsockopt(PACKET_RECV_TYPE): %m"); + error("setsockopt(PACKET_RECV_TYPE): %m"); ret = -1; goto out; } @@ -172,7 +172,7 @@ int ndp_setup_interface(struct interface *iface, bool enable) if (setsockopt(iface->ndp_event.uloop.fd, SOL_SOCKET, SO_ATTACH_FILTER, &bpf_prog, sizeof(bpf_prog))) { - syslog(LOG_ERR, "setsockopt(SO_ATTACH_FILTER): %m"); + error("setsockopt(SO_ATTACH_FILTER): %m"); ret = -1; goto out; } @@ -183,7 +183,7 @@ int ndp_setup_interface(struct interface *iface, bool enable) ll.sll_protocol = htons(ETH_P_IPV6); if (bind(iface->ndp_event.uloop.fd, (struct sockaddr*)&ll, sizeof(ll)) < 0) { - syslog(LOG_ERR, "bind(): %m"); + error("bind(): %m"); ret = -1; goto out; } @@ -195,7 +195,7 @@ int ndp_setup_interface(struct interface *iface, bool enable) if (setsockopt(iface->ndp_event.uloop.fd, SOL_PACKET, PACKET_ADD_MEMBERSHIP, &mreq, sizeof(mreq)) < 0) { - syslog(LOG_ERR, "setsockopt(PACKET_ADD_MEMBERSHIP): %m"); + error("setsockopt(PACKET_ADD_MEMBERSHIP): %m"); ret = -1; goto out; } @@ -288,7 +288,7 @@ static void ping6(struct in6_addr *addr, char ipbuf[INET6_ADDRSTRLEN]; inet_ntop(AF_INET6, addr, ipbuf, sizeof(ipbuf)); - syslog(LOG_DEBUG, "Pinging for %s on %s", ipbuf, iface->name); + debug("Pinging for %s on %s", ipbuf, iface->name); netlink_setup_route(addr, 128, iface->ifindex, NULL, 128, true); @@ -320,7 +320,7 @@ static void send_na(struct in6_addr *to_addr, memcpy(&pbuf[sizeof(struct nd_neighbor_advert) + sizeof(struct nd_opt_hdr)], mac, 6); inet_ntop(AF_INET6, to_addr, ipbuf, sizeof(ipbuf)); - syslog(LOG_DEBUG, "Answering NS to %s on %s", ipbuf, iface->ifname); + debug("Answering NS to %s on %s", ipbuf, iface->ifname); /* Use link-local address as source for RFC 4861 compliance and macOS compatibility */ odhcpd_try_send_with_src(iface->ndp_ping_fd, &dest, &iov, 1, iface); @@ -356,7 +356,7 @@ static void handle_solicit(void *addr, void *data, size_t len, return; /* Invalid target */ inet_ntop(AF_INET6, &req->nd_ns_target, ipbuf, sizeof(ipbuf)); - syslog(LOG_DEBUG, "Got a NS for %s on %s", ipbuf, iface->name); + debug("Got a NS for %s on %s", ipbuf, iface->name); odhcpd_get_mac(iface, mac); is_self_sent = !memcmp(ll->sll_addr, mac, sizeof(mac)); @@ -387,10 +387,10 @@ static void setup_route(struct in6_addr *addr, struct interface *iface, bool add char ipbuf[INET6_ADDRSTRLEN]; inet_ntop(AF_INET6, addr, ipbuf, sizeof(ipbuf)); - syslog(LOG_DEBUG, "%s about %s%s on %s", - (add) ? "Learning" : "Forgetting", - iface->learn_routes ? "proxy routing for " : "", - ipbuf, iface->name); + debug("%s about %s%s on %s", + (add) ? "Learning" : "Forgetting", + iface->learn_routes ? "proxy routing for " : "", + ipbuf, iface->name); if (iface->learn_routes) netlink_setup_route(addr, 128, iface->ifindex, NULL, 1024, add); @@ -409,10 +409,10 @@ static void setup_addr_for_relaying(struct in6_addr *addr, struct interface *ifa if (netlink_setup_proxy_neigh(addr, c->ifindex, add)) { if (add) - syslog(LOG_ERR, "Failed to add proxy neighbour entry %s on %s", - ipbuf, c->name); + error("Failed to add proxy neighbour entry %s on %s", + ipbuf, c->name); } else - syslog(LOG_DEBUG, "%s proxy neighbour entry %s on %s", - add ? "Added" : "Deleted", ipbuf, c->name); + debug("%s proxy neighbour entry %s on %s", + add ? "Added" : "Deleted", ipbuf, c->name); } } diff --git a/src/netlink.c b/src/netlink.c index 57cf566..5b3dc66 100644 --- a/src/netlink.c +++ b/src/netlink.c @@ -14,7 +14,6 @@ #include #include -#include #include #include @@ -58,13 +57,13 @@ int netlink_init(void) { rtnl_socket = create_socket(NETLINK_ROUTE); if (!rtnl_socket) { - syslog(LOG_ERR, "Unable to open nl socket: %m"); + error("Unable to open nl socket: %m"); goto err; } rtnl_event.sock = create_socket(NETLINK_ROUTE); if (!rtnl_event.sock) { - syslog(LOG_ERR, "Unable to open nl event socket: %m"); + error("Unable to open nl event socket: %m"); goto err; } @@ -352,8 +351,8 @@ static int handle_rtm_addr(struct nlmsghdr *hdr, bool add) return NL_SKIP; } - syslog(LOG_DEBUG, "Netlink %s %s on %s", add ? "newaddr" : "deladdr", - buf, iface->name); + debug("Netlink %s %s on %s", add ? "newaddr" : "deladdr", + buf, iface->name); event_info.iface = iface; call_netevent_handler_list(add ? NETEV_ADDR6_ADD : NETEV_ADDR6_DEL, @@ -373,8 +372,8 @@ static int handle_rtm_addr(struct nlmsghdr *hdr, bool add) if (iface->ifindex != (int)ifa->ifa_index) continue; - syslog(LOG_DEBUG, "Netlink %s %s on %s", add ? "newaddr" : "deladdr", - buf, iface->name); + debug("Netlink %s %s on %s", add ? "newaddr" : "deladdr", + buf, iface->name); event_info.iface = iface; call_netevent_handler_list(add ? NETEV_ADDR_ADD : NETEV_ADDR_DEL, @@ -417,8 +416,8 @@ static int handle_rtm_neigh(struct nlmsghdr *hdr, bool add) if (iface->ifindex != ndm->ndm_ifindex) continue; - syslog(LOG_DEBUG, "Netlink %s %s on %s", true ? "newneigh" : "delneigh", - buf, iface->name); + debug("Netlink %s %s on %s", true ? "newneigh" : "delneigh", + buf, iface->name); event_info.iface = iface; event_info.neigh.state = ndm->ndm_state; diff --git a/src/odhcpd.c b/src/odhcpd.c index 5116ba3..6b07f0e 100644 --- a/src/odhcpd.c +++ b/src/odhcpd.c @@ -24,7 +24,6 @@ #include #include #include -#include #include #include @@ -115,7 +114,7 @@ int main(int argc, char **argv) uloop_init(); if (getuid() != 0) { - syslog(LOG_ERR, "Must be run as root!"); + error("Must be run as root!"); return 2; } @@ -245,11 +244,11 @@ ssize_t odhcpd_send_with_src(int socket, struct sockaddr_in6 *dest, ssize_t sent = sendmsg(socket, &msg, MSG_DONTWAIT); if (sent < 0) - syslog(LOG_ERR, "Failed to send to %s%%%s@%s (%m)", - ipbuf, iface->name, iface->ifname); + error("Failed to send to %s%%%s@%s (%m)", + ipbuf, iface->name, iface->ifname); else - syslog(LOG_DEBUG, "Sent %zd bytes to %s%%%s@%s", - sent, ipbuf, iface->name, iface->ifname); + debug("Sent %zd bytes to %s%%%s@%s", + sent, ipbuf, iface->name, iface->ifname); return sent; } @@ -474,8 +473,7 @@ static void odhcpd_receive_packets(struct uloop_fd *u, _unused unsigned int even /* From netlink */ if (addr.nl.nl_family == AF_NETLINK) { - syslog(LOG_DEBUG, "Received %zd Bytes from %s%%netlink", len, - ipbuf); + debug("Received %zd Bytes from %s%%netlink", len, ipbuf); e->handle_dgram(&addr, data_buf, len, NULL, dest); return; } else if (destiface != 0) { @@ -485,8 +483,8 @@ static void odhcpd_receive_packets(struct uloop_fd *u, _unused unsigned int even if (iface->ifindex != destiface) continue; - syslog(LOG_DEBUG, "Received %zd Bytes from %s%%%s@%s", len, - ipbuf, iface->name, iface->ifname); + debug("Received %zd Bytes from %s%%%s@%s", len, + ipbuf, iface->name, iface->ifname); e->handle_dgram(&addr, data_buf, len, iface, dest); } diff --git a/src/odhcpd.h b/src/odhcpd.h index d428fbe..0cda056 100644 --- a/src/odhcpd.h +++ b/src/odhcpd.h @@ -69,6 +69,22 @@ struct nl_sock; extern struct vlist_tree leases; extern struct config config; +#define __iflog(lvl, fmt, ...) \ + do { \ + if (lvl <= config.log_level) \ + syslog(lvl, fmt __VA_OPT__(, ) __VA_ARGS__); \ + } while(0) + +#define debug(fmt, ...) __iflog(LOG_DEBUG, fmt __VA_OPT__(, ) __VA_ARGS__) +#define info(fmt, ...) __iflog(LOG_INFO, fmt __VA_OPT__(, ) __VA_ARGS__) +#define notice(fmt, ...) __iflog(LOG_NOTICE, fmt __VA_OPT__(, ) __VA_ARGS__) +#define warn(fmt, ...) __iflog(LOG_WARNING, fmt __VA_OPT__(, ) __VA_ARGS__) +#define error(fmt, ...) __iflog(LOG_ERR, fmt __VA_OPT__(, ) __VA_ARGS__) +#define critical(fmt, ...) __iflog(LOG_CRIT, fmt __VA_OPT__(, ) __VA_ARGS__) +#define alert(fmt, ...) __iflog(LOG_ALERT, fmt __VA_OPT__(, ) __VA_ARGS__) +#define emergency(fmt, ...) __iflog(LOG_EMERG, fmt __VA_OPT__(, ) __VA_ARGS__) + + struct odhcpd_event { struct uloop_fd uloop; void (*handle_dgram)(void *addr, void *data, size_t len, diff --git a/src/router.c b/src/router.c index fd8e9e3..f841b2f 100644 --- a/src/router.c +++ b/src/router.c @@ -50,13 +50,13 @@ int router_init(void) int ret = 0; if (!(fp_route = fopen("/proc/net/ipv6_route", "r"))) { - syslog(LOG_ERR, "fopen(/proc/net/ipv6_route): %m"); + error("fopen(/proc/net/ipv6_route): %m"); ret = -1; goto out; } if (netlink_add_netevent_handler(&router_netevent_handler) < 0) { - syslog(LOG_ERR, "Failed to add netevent handler"); + error("Failed to add netevent handler"); ret = -1; } @@ -103,14 +103,14 @@ int router_setup_interface(struct interface *iface, bool enable) iface->router_event.uloop.fd = socket(AF_INET6, SOCK_RAW | SOCK_CLOEXEC, IPPROTO_ICMPV6); if (iface->router_event.uloop.fd < 0) { - syslog(LOG_ERR, "socket(AF_INET6): %m"); + error("socket(AF_INET6): %m"); ret = -1; goto out; } if (setsockopt(iface->router_event.uloop.fd, SOL_SOCKET, SO_BINDTODEVICE, iface->ifname, strlen(iface->ifname)) < 0) { - syslog(LOG_ERR, "setsockopt(SO_BINDTODEVICE): %m"); + error("setsockopt(SO_BINDTODEVICE): %m"); ret = -1; goto out; } @@ -118,7 +118,7 @@ int router_setup_interface(struct interface *iface, bool enable) /* Let the kernel compute our checksums */ if (setsockopt(iface->router_event.uloop.fd, IPPROTO_RAW, IPV6_CHECKSUM, &val, sizeof(val)) < 0) { - syslog(LOG_ERR, "setsockopt(IPV6_CHECKSUM): %m"); + error("setsockopt(IPV6_CHECKSUM): %m"); ret = -1; goto out; } @@ -127,14 +127,14 @@ int router_setup_interface(struct interface *iface, bool enable) val = 255; if (setsockopt(iface->router_event.uloop.fd, IPPROTO_IPV6, IPV6_MULTICAST_HOPS, &val, sizeof(val)) < 0) { - syslog(LOG_ERR, "setsockopt(IPV6_MULTICAST_HOPS): %m"); + error("setsockopt(IPV6_MULTICAST_HOPS): %m"); ret = -1; goto out; } if (setsockopt(iface->router_event.uloop.fd, IPPROTO_IPV6, IPV6_UNICAST_HOPS, &val, sizeof(val)) < 0) { - syslog(LOG_ERR, "setsockopt(IPV6_UNICAST_HOPS): %m"); + error("setsockopt(IPV6_UNICAST_HOPS): %m"); ret = -1; goto out; } @@ -143,14 +143,14 @@ int router_setup_interface(struct interface *iface, bool enable) val = 1; if (setsockopt(iface->router_event.uloop.fd, IPPROTO_IPV6, IPV6_RECVPKTINFO, &val, sizeof(val)) < 0) { - syslog(LOG_ERR, "setsockopt(IPV6_RECVPKTINFO): %m"); + error("setsockopt(IPV6_RECVPKTINFO): %m"); ret = -1; goto out; } if (setsockopt(iface->router_event.uloop.fd, IPPROTO_IPV6, IPV6_RECVHOPLIMIT, &val, sizeof(val)) < 0) { - syslog(LOG_ERR, "setsockopt(IPV6_RECVHOPLIMIT): %m"); + error("setsockopt(IPV6_RECVHOPLIMIT): %m"); ret = -1; goto out; } @@ -159,7 +159,7 @@ int router_setup_interface(struct interface *iface, bool enable) val = 0; if (setsockopt(iface->router_event.uloop.fd, IPPROTO_IPV6, IPV6_MULTICAST_LOOP, &val, sizeof(val)) < 0) { - syslog(LOG_ERR, "setsockopt(IPV6_MULTICAST_LOOP): %m"); + error("setsockopt(IPV6_MULTICAST_LOOP): %m"); ret = -1; goto out; } @@ -170,7 +170,7 @@ int router_setup_interface(struct interface *iface, bool enable) ICMP6_FILTER_SETPASS(ND_ROUTER_SOLICIT, &filt); if (setsockopt(iface->router_event.uloop.fd, IPPROTO_ICMPV6, ICMP6_FILTER, &filt, sizeof(filt)) < 0) { - syslog(LOG_ERR, "setsockopt(ICMP6_FILTER): %m"); + error("setsockopt(ICMP6_FILTER): %m"); ret = -1; goto out; } @@ -208,7 +208,7 @@ int router_setup_interface(struct interface *iface, bool enable) if (setsockopt(iface->router_event.uloop.fd, IPPROTO_IPV6, IPV6_ADD_MEMBERSHIP, &mreq, sizeof(mreq)) < 0) { ret = -1; - syslog(LOG_ERR, "setsockopt(IPV6_ADD_MEMBERSHIP): %m"); + error("setsockopt(IPV6_ADD_MEMBERSHIP): %m"); goto out; } } @@ -463,10 +463,10 @@ static void router_add_ra_pio(struct interface *iface, pio->lifetime = 0; iface->pio_update = true; - syslog(LOG_WARNING, "rfc9096: %s: renew %s/%u", - iface->ifname, - inet_ntop(AF_INET6, &pio->prefix, ipv6_str, sizeof(ipv6_str)), - pio->length); + warn("rfc9096: %s: renew %s/%u", + iface->ifname, + inet_ntop(AF_INET6, &pio->prefix, ipv6_str, sizeof(ipv6_str)), + pio->length); } return; @@ -485,10 +485,10 @@ static void router_add_ra_pio(struct interface *iface, pio->lifetime = 0; iface->pio_update = true; - syslog(LOG_INFO, "rfc9096: %s: add %s/%u", - iface->ifname, - inet_ntop(AF_INET6, &pio->prefix, ipv6_str, sizeof(ipv6_str)), - pio->length); + info("rfc9096: %s: add %s/%u", + iface->ifname, + inet_ntop(AF_INET6, &pio->prefix, ipv6_str, sizeof(ipv6_str)), + pio->length); } static void router_clear_ra_pio(time_t now, @@ -501,11 +501,10 @@ static void router_clear_ra_pio(time_t now, struct ra_pio *cur_pio = &iface->pios[i]; if (ra_pio_expired(cur_pio, now)) { - syslog(LOG_INFO, - "rfc9096: %s: clear %s/%u", - iface->ifname, - inet_ntop(AF_INET6, &cur_pio->prefix, ipv6_str, sizeof(ipv6_str)), - cur_pio->length); + info("rfc9096: %s: clear %s/%u", + iface->ifname, + inet_ntop(AF_INET6, &cur_pio->prefix, ipv6_str, sizeof(ipv6_str)), + cur_pio->length); if (i + 1 < iface->pio_cnt) iface->pios[i] = iface->pios[iface->pio_cnt - 1]; @@ -540,10 +539,10 @@ static void router_stale_ra_pio(struct interface *iface, pio->lifetime = now + iface->max_valid_lifetime; iface->pio_update = true; - syslog(LOG_WARNING, "rfc9096: %s: stale %s/%u", - iface->ifname, - inet_ntop(AF_INET6, &pio->prefix, ipv6_str, sizeof(ipv6_str)), - pio->length); + warn("rfc9096: %s: stale %s/%u", + iface->ifname, + inet_ntop(AF_INET6, &pio->prefix, ipv6_str, sizeof(ipv6_str)), + pio->length); } /* Router Advert server mode */ @@ -670,16 +669,16 @@ static int send_router_advert(struct interface *iface, const struct in6_addr *fr uint32_t valid_lt = 0; if (addr->prefix > 96 || (i < valid_addr_cnt && addr->valid_lt <= (uint32_t)now)) { - syslog(LOG_INFO, "Address %s (prefix %d, valid-lifetime %u) not suitable as RA prefix on %s", - inet_ntop(AF_INET6, &addr->addr.in6, buf, sizeof(buf)), addr->prefix, - addr->valid_lt, iface->name); + info("Address %s (prefix %d, valid-lifetime %u) not suitable as RA prefix on %s", + inet_ntop(AF_INET6, &addr->addr.in6, buf, sizeof(buf)), addr->prefix, + addr->valid_lt, iface->name); continue; } if (ADDR_MATCH_PIO_FILTER(addr, iface)) { - syslog(LOG_INFO, "Address %s filtered out as RA prefix on %s", - inet_ntop(AF_INET6, &addr->addr.in6, buf, sizeof(buf)), - iface->name); + info("Address %s filtered out as RA prefix on %s", + inet_ntop(AF_INET6, &addr->addr.in6, buf, sizeof(buf)), + iface->name); continue; /* PIO filtered out of this RA */ } @@ -695,7 +694,7 @@ static int send_router_advert(struct interface *iface, const struct in6_addr *fr tmp = realloc(pfxs, sizeof(*pfxs) * (pfxs_cnt + 1)); if (!tmp) { - syslog(LOG_ERR, "Realloc failed for RA prefix option on %s", iface->name); + error("Realloc failed for RA prefix option on %s", iface->name); continue; } @@ -783,7 +782,7 @@ static int send_router_advert(struct interface *iface, const struct in6_addr *fr highest_found_lifetime = ra_lifetime; if (!iface->have_link_local) { - syslog(LOG_NOTICE, "Skip sending a RA on %s as no link local address is available", iface->name); + notice("Skip sending a RA on %s as no link local address is available", iface->name); goto out; } @@ -792,15 +791,14 @@ static int send_router_advert(struct interface *iface, const struct in6_addr *fr } else { adv.h.nd_ra_router_lifetime = 0; - if (default_route) { - syslog(LOG_WARNING, "A default route is present but there is no public prefix " - "on %s thus we announce no default route by setting ra_lifetime to 0!", iface->name); - } else { - syslog(LOG_WARNING, "No default route present, setting ra_lifetime to 0!"); - } + if (default_route) + warn("A default route is present but there is no public prefix " + "on %s thus we announce no default route by setting ra_lifetime to 0!", iface->name); + else + warn("No default route present, setting ra_lifetime to 0!"); } - syslog(LOG_DEBUG, "Using a RA lifetime of %d seconds on %s", ntohs(adv.h.nd_ra_router_lifetime), iface->name); + debug("Using a RA lifetime of %d seconds on %s", ntohs(adv.h.nd_ra_router_lifetime), iface->name); /* DNS options */ if (iface->ra_dns) { @@ -938,17 +936,17 @@ static int send_router_advert(struct interface *iface, const struct in6_addr *fr uint32_t valid_lt; if (addr->dprefix >= 64 || addr->dprefix == 0 || addr->valid_lt <= (uint32_t)now) { - syslog(LOG_INFO, "Address %s (dprefix %d, valid-lifetime %u) not suitable as RA route on %s", - inet_ntop(AF_INET6, &addr->addr.in6, buf, sizeof(buf)), - addr->dprefix, addr->valid_lt, iface->name); + info("Address %s (dprefix %d, valid-lifetime %u) not suitable as RA route on %s", + inet_ntop(AF_INET6, &addr->addr.in6, buf, sizeof(buf)), + addr->dprefix, addr->valid_lt, iface->name); continue; /* Address not suitable */ } if (ADDR_MATCH_PIO_FILTER(addr, iface)) { - syslog(LOG_INFO, "Address %s filtered out as RA route on %s", - inet_ntop(AF_INET6, &addr->addr.in6, buf, sizeof(buf)), - iface->name); + info("Address %s filtered out as RA route on %s", + inet_ntop(AF_INET6, &addr->addr.in6, buf, sizeof(buf)), + iface->name); continue; /* PIO filtered out of this RA */ } @@ -961,7 +959,7 @@ static int send_router_advert(struct interface *iface, const struct in6_addr *fr tmp = realloc(routes, sizeof(*routes) * (routes_cnt + 1)); if (!tmp) { - syslog(LOG_ERR, "Realloc failed for RA route option on %s", iface->name); + error("Realloc failed for RA route option on %s", iface->name); continue; } @@ -1008,7 +1006,7 @@ static int send_router_advert(struct interface *iface, const struct in6_addr *fr else inet_pton(AF_INET6, ALL_IPV6_NODES, &dest.sin6_addr); - syslog(LOG_DEBUG, "Sending a RA on %s", iface->name); + debug("Sending a RA on %s", iface->name); if (odhcpd_send(iface->router_event.uloop.fd, &dest, iov, ARRAY_SIZE(iov), iface) > 0) { iface->ra_sent++; @@ -1079,7 +1077,7 @@ static void forward_router_solicitation(const struct interface *iface) inet_pton(AF_INET6, ALL_IPV6_ROUTERS, &all_routers.sin6_addr); all_routers.sin6_scope_id = iface->ifindex; - syslog(LOG_NOTICE, "Sending RS to %s", iface->name); + notice("Sending RS to %s", iface->name); odhcpd_send(iface->router_event.uloop.fd, &all_routers, &iov, 1, iface); } @@ -1109,7 +1107,7 @@ static void forward_router_advertisement(const struct interface *iface, uint8_t } } - syslog(LOG_NOTICE, "Got a RA on %s", iface->name); + notice("Got a RA on %s", iface->name); /* Indicate a proxy, however we don't follow the rest of RFC 4389 yet */ adv->nd_ra_flags_reserved |= ND_RA_FLAG_PROXY; @@ -1148,7 +1146,7 @@ static void forward_router_advertisement(const struct interface *iface, uint8_t } } - syslog(LOG_NOTICE, "Forward a RA on %s", c->name); + notice("Forward a RA on %s", c->name); odhcpd_send(c->router_event.uloop.fd, &all_nodes, &iov, 1, c); } diff --git a/src/ubus.c b/src/ubus.c index 987e0b4..47282da 100644 --- a/src/ubus.c +++ b/src/ubus.c @@ -1,4 +1,3 @@ -#include #include #include #include @@ -501,7 +500,7 @@ bool ubus_has_prefix(const char *name, const char *ifname) int ubus_init(void) { if (!(ubus = ubus_connect(NULL))) { - syslog(LOG_ERR, "Unable to connect to ubus: %m"); + error("Unable to connect to ubus: %m"); return -1; } -- 2.30.2